package com.zyf.mt.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zyf.mt.domain.Driver;
import com.zyf.mt.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/driver/")
public class DriverController {

    @Autowired
    DriverService driverService;

    List<Driver> driverList;
    @RequestMapping("save")
    public String save(HttpServletRequest request,Driver driver){
        System.out.println(driver.toString());
        //保存数据
        driverService.save(driver);
        QueryWrapper<Driver> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        driverList = driverService.list(wrapper);
        request.setAttribute("driverList",driverList);
        return "driverList";
    }

    @RequestMapping("list")
    public String list(HttpServletRequest request){
        QueryWrapper<Driver> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        driverList = driverService.list(wrapper);
        request.setAttribute("driverList",driverList);
        return "driverList";
    }

}